﻿using System;
using System.Linq;
using Stamp_For_Africa_Version_2.Models;

namespace Stamp_For_Africa_Version_2.Repositories
{
  public class CountryRepository
  {
    private StampsDataContext db = new StampsDataContext();
    //
    // Query Methods

    public IQueryable<Country> FindAllCountries()
    {
      return db.Countries;
    }

    public IQueryable<Country> FindAllCountries(String filter)
    {
      //Filter code comes here
      return db.Countries.Where(u => u.Name.ToLower().Contains(filter.ToLower()));

    }

    public Country GetCountry(Guid id)
    {
      return db.Countries.SingleOrDefault(d => d.Id == id);
    }

    //
    // Insert/Delete Methods

    public void Add(Country country)
    {
      db.Countries.InsertOnSubmit(country);
    }

    public void Delete(Country country)
    {
      db.Countries.DeleteOnSubmit(country);
    }

    //
    // Persistence

    public void Save()
    {
      db.SubmitChanges();
    }
  }
}